package com.mall.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mall.db.domain.Comment;
import com.mall.db.service.CommentService;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/system/ccc")
public class CommentController extends BaseController<Comment>{
    @Resource(name = "commentService")
    private CommentService cs;

    @Override
    public Map<String, Object> find(Comment comment) {
        PageHelper.startPage(comment.getPage(),comment.getLimit());
        QueryWrapper qw=new QueryWrapper();
        List<Comment> list=cs.list(qw);
        PageInfo<Comment> page=new PageInfo<>(list,comment.getLimit());

        return this.findMap(page.getList(),page.getTotal());
    }

    @Override
    public Map<String, Object> update(Comment comment) {
        Comment c=cs.getById(comment.getId());
        if(!StringUtils.isEmpty(c.getReply())){
            c.setReply(c.getReply()+"|"+comment.getReply());
        }else {
            c.setReply(comment.getReply());
        }

        boolean b=cs.updateById(c);
        return this.iud("回复",b,c);
    }

    @Override
    public Map<String, Object> delete(Comment comment) {

      boolean b=cs.removeById(comment.getId());


        return this.iud("删除",b,comment);
    }
}
